package com.example.demo.controller;

import com.example.demo.model.Blog;
import com.example.demo.model.User;
import com.example.demo.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;

@RestController
public class EditController {
    @Autowired
    private BlogService blogService;

    @RequestMapping("/edit")
    public void postBlog(@RequestBody Blog blog, @SessionAttribute(value = "user",required = false)User user){
        blog.setPostTime(new Timestamp(System.currentTimeMillis()));
        blog.setUserId(user.getUserId());

        blogService.postBlog(blog);
    }
}
